package com.google.code.openperfmon.web.admin;

import java.util.List;

import com.google.code.openperfmon.domain.MonitorDefinition;
import com.google.code.openperfmon.service.AdminEntityInfo;
import com.google.code.openperfmon.service.ReferenceExistException;
import com.google.code.openperfmon.service.ServiceFactory;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class ManageMonitorDefinitionsAction extends ActionSupport {	
	private Long id;
	private List<AdminEntityInfo<MonitorDefinition>> definitions;
	
	public String list() throws Exception {
		definitions = ServiceFactory.getMonitorDefinitionService().listMonitorDefinitions();
		return SUCCESS;
	}

	public String delete() throws Exception {
		try {
			ServiceFactory.getMonitorDefinitionService().deleteMonitorDefinition(id);
		}
		catch (ReferenceExistException e) {
			addActionError(e.getMessage());
		}
		return SUCCESS;
	}
	
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public List<AdminEntityInfo<MonitorDefinition>> getDefinitions() {
		return definitions;
	}
	public void setDefinitions(List<AdminEntityInfo<MonitorDefinition>> definitions) {
		this.definitions = definitions;
	}
}
